<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <script>
    function test(){
      //1.创建xhr对象
      var xhr = new XMLHttpRequest();

      //1.5 处理结果
      xhr.onreadystatechange = function(){
        if(xhr.status==200 && xhr.readyState==4){
          console.log(xhr.responseText);
          document.getElementById("msg").innerText="返回结果为: "+xhr.responseText;

        }
      }

      //2.发送请求
      xhr.open("GET","http://localhost:8443/demos");
      xhr.send();
    }
  </script>
</head>
<body>


  <h1>cors 跨域测试</h1>

  <input type="button" value="点我发送ajax请求" onclick="test()">

  <h4 id="msg"></h4>

</body>
</html>